package app.util.image.action
{
	import app.util.*;
	
	import flash.display.*;
	import flash.filters.ColorMatrixFilter;
	import flash.geom.*;
	
	public class InvertAction extends AbstractAction
	{
		private var fade:Number;
		public function setValue(fade:Number):InvertAction
		{
			this.fade = fade;
			return this;
		}
		
		public override function getDescription():String
		{
			return "Invert (" + this.fade.toFixed(0) + ")";
		}
		
		public override function getActionedBitmapData():BitmapData
		{
			var mat:Array =  [-1, 0, 0, 0, 255, 
							 0, -1, 0, 0, 255,
							 0, 0, -1, 0, 255,
							 0, 0, 0, 1, 0];
			var old:BitmapData = Mediator.getCurrentBitmapData();
			var ret:BitmapData = old.clone();
			var filter:ColorMatrixFilter = new ColorMatrixFilter(mat);
			ret.applyFilter(ret, ret.rect, new Point(0, 0), filter);
			ret.merge(old, ret.rect, new Point(0,0), 256-fade,
				256-fade, 256-fade, 256-fade);
			return ret;
		}	
	
		
		
	}
}